import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import operiation.*;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Scanner;

/**
 * Creater with IntelliJ IDEA.
 * Description:
 * User: 86152
 * Dae: 2022-07-18
 * Time: 21:22
 */
public class student {
    public static void main(String[] args) throws SQLException {
        //1.描述mysql数据库位置
        DataSource dataSource = new MysqlDataSource();
        ((MysqlDataSource)dataSource).setURL("jdbc:mysql://127.0.0.1:3306/ebook?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource)dataSource).setUser("root");
        ((MysqlDataSource)dataSource).setPassword("760121");

        //2.建立连接
        Connection connection = dataSource.getConnection();

        //选择操作
        System.out.println("1.插入 2.删除 3.查找 4.修改");
        while(true) {
            int input;
            Scanner scanner = new Scanner(System.in);
            input=scanner.nextInt();
            switch (input) {
                case 1:
                    System.out.println(insert.work(dataSource,connection));
                    break;
                case 2:
                    System.out.println(delete.work(dataSource,connection));
                    break;
                case 3:
                    search.work(dataSource,connection);
                case 4:
                    System.out.println(modify.work(dataSource,connection));
            }
        }
    }
}
